package com.sino.operation.service.business;

import com.sino.operation.peripheral.esc.core.param.Core_2110_param;
import com.sino.operation.peripheral.esc.core.param.Core_2117_param;
import com.sino.operation.peripheral.esc.core.param.Core_2157_param;
import com.sino.operation.peripheral.esc.core.param.Core_2158_param;
import com.sino.operation.peripheral.esc.core.vo.Core_2110_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2117_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2157_VO;
import com.sino.operation.peripheral.esc.core.vo.Core_2158_VO;
import com.sino.operation.service.business.inter.CoreTestService;
import com.sino.operation.util.EscUtil;
import com.sino.operation.util.RestTemplateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * @ClassName CoreTestServiceImpl
 * @Description TOD
 * @Author 北陈
 * @Date 2021/10/11 14:46
 * @Version 1.0
 */
@Service
@Slf4j
public class CoreTestServiceImpl implements CoreTestService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private EscUtil escUtil;

    @Autowired
    private RestTemplateUtils restTemplateUtils;
    @Override
    public Core_2110_VO startCore2110() {
        Core_2110_param core2110Param =
        Core_2110_param.builder().acctAttr("152").custNum("156565").openAcctQuickFlg("0")
                .ccyCodeNum("156").prodCode("1565656").acctClasf("45").custTp("0").unvslWthdgFlg("0")
                .pymtCond("0").wthrSelfChcNum("0").intCalnFlg("0").build();

        String escToken = redisTemplate.opsForValue().get("escToken");
        Map<String, Object> map = escUtil.escTest(escToken, "sxyh", "xy0001", "dp2110");
        String url = (String) map.get("url");
        log.info("2110地址:",url);
        ResponseEntity<Core_2110_VO> post = restTemplateUtils.post(url, core2110Param, Core_2110_VO.class);
        Core_2110_VO body = post.getBody();
        return body;
    }

    @Override
    public Core_2157_VO startCore2157() {
        Core_2157_param core2157Param=
        Core_2157_param.builder().custAcctNum("45455465656").subAcctSerlNum("45565656").build();
        String escToken = redisTemplate.opsForValue().get("escToken");
        Map<String, Object> map = escUtil.escTest(escToken, "sxyh", "xy0001", "dp2157");
        String url = (String) map.get("url");
        log.info("2157地址:",url);
        ResponseEntity<Core_2157_VO> post = restTemplateUtils.post(url, core2157Param, Core_2157_VO.class);
        Core_2157_VO body = post.getBody();
        return body;
    }

    @Override
    public Core_2158_VO startCore2158() {
        Core_2158_param core2158Param = Core_2158_param.builder().custAcctNum("454515616").build();
        String escToken = redisTemplate.opsForValue().get("escToken");
        Map<String, Object> map = escUtil.escTest(escToken, "sxyh", "xy0001", "dp2158");
        String url = (String) map.get("url");
        log.info("2158地址:",url);
        ResponseEntity<Core_2158_VO> post = restTemplateUtils.post(url, core2158Param, Core_2158_VO.class);
        Core_2158_VO body = post.getBody();
        return body;
    }

    @Override
    public Core_2117_VO startCore2117() {
        Core_2117_param core2117Param=
        Core_2117_param.builder().cnclAcctWay("0").custAcctNum("1212121212")
                .subAcctSerlNum("454545656").cptlDrcn("0").build();
        String escToken = redisTemplate.opsForValue().get("escToken");
        Map<String, Object> map = escUtil.escTest(escToken, "sxyh", "xy0001", "dp2117");
        String url = (String) map.get("url");
        log.info("2117地址:",url);
        ResponseEntity<Core_2117_VO> post = restTemplateUtils.post(url, core2117Param, Core_2117_VO.class);
        Core_2117_VO body = post.getBody();
        return body;
    }
}
